<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Activeprojects extends CI_Controller {
	
	var $logged = FALSE;
	
	public function __construct(){
		parent::__construct ();
		if($this->session->userdata('loggedin')) $this->logged=TRUE;
	}
	
	public function index()
	{
		$this->page(1);
	}
	
	public function page($index){
		$this->lang->load('site', get_lang());
		$class='';
		$pages = '<div class="btn-group pull-right" style="margin-bottom: 15px">';
		
		$this->db->from('projects');
		$qtd = $this->db->count_all_results();
		$count=0;
		if($qtd>10){
			$pages.='<a class="btn btn-small btn-inverse disabled" href="#">'.lang('word_pages').':</a>';
			for ($i=0; $i<=$qtd; $i+=10){
				$count++;
				if($count == $index){
					$pages.='<a class="btn btn-small active" href="'.base_url().'activeprojects/page/'.$count.'">'.$count.'</a>';
				}else{
					$pages.='<a class="btn btn-small" href="'.base_url().'activeprojects/page/'.$count.'">'.$count.'</a>';
				}
				
			}
		}
		$pages.= '</div>';		
		
		$data['content'] = $pages.$this->showProjects($index).$pages;
		$data['page'] = 'pages/activeprojects';
		$this->load->view('mainview', $data);
	}
	
	
	public function showProjects($index){
		$this->load->helper('date');
		$this->db->select('*');
		$this->db->from('projects');
		$this->db->limit(10,10*($index-1));
		
		$query = $this->db->get();
		$print='<table class="table table-striped table-bordered">
		<thead>
			<tr>
				<td></td>
				<td>'.lang("active_projects_details").'</td>
				<td>'.lang("active_projects_final_date").'</td>
				<td>'.lang("active_projects_premium").'</td>
			</tr>
		</thead>
		<tbody>';
		foreach ($query->result() as $row){
			$print .= '<tr>';
			$print .= '<td width="65"><img class="pull-left" alt="image" src="'.base_url().'assets/img/icons/hanger3.png"/></td>';
			$print .= '<td><strong>'.$row->nm_project.'</strong><br/>'.$row->ds_description.'</td>';
			$print .= '<td width="90">'.mysqldatetime_to_date($row->dt_end).'</td>';
			if ($this->logged) {
				$print .= '<td width="90" style="text-align:center"><h4>R$ '.$row->vl_value.'</h2><a href="'.base_url().'project/view/'.$row->id_project.'" class="btn btn-success">'.lang('active_projects_visualize').'</a></td>';
			}else{
				$print .= '<td width="90" style="text-align:center"><h4>R$ '.$row->vl_value.'</h2></td>';
			}
			
			$print .= '</tr>';
		}
		$print .= '</tbody></table> ';
		return $print;
	}
}
